<template>
	<view class="page">
		<block v-for="(infoItem, infoItemIndex) in myInfoList" :key="infoItem.ID">
			<view class="info-item" :class="infoItem.IsTop == '2'? 'info-item-vip' : infoItem.IsTop == '1'? 'info-item-top' : ''" @click.stop="gotoInfoContent(infoItem.ID)">
				<view class="info-item-head">
					<image :src="$getImgUrl(infoItem.WXImg)" alt="" class="info-userface" mode="aspectFill"></image>
					<view class="info-item-briefing">
						<view class="info-briefing-title">
							<view class="info-briefing-class">
								{{infoItem.LMName}}
							</view>
							<view class="info-briefing-name">
								{{infoItem.Person}}
							</view>
						</view>
						<view class="info-briefing-tag">
							<view class="info-briefing-tag-item" v-for="(lddataItem,lddataIndex) in infoItem.lddata" :key="lddataIndex">
								{{lddataItem.LiangDian}}
							</view>
						</view>
					</view>
				</view>
				<view class="info-item-content">
					{{infoItem.Content}}<text class="info-item-content-more">查看全部>></text>
				</view>
				<view class="info-item-img-group">
					<block v-for="(infoItemImg,infoItemImgIndex) in infoItem.tpdata" :key="infoItemImgIndex">
					<image :src="$getImgUrl(infoItemImg.imgpath)" mode="aspectFill" class="info-item-img" @click.stop="infoimagePreview(infoItemImgIndex,infoItemIndex)"></image>
					</block>
				</view>
				<view class="info-item-addtel">
					<view class="info-item-addres">
						<image src="../../static/infoIco/map.png" mode="scaleToFill" class="info-item-addresimg"></image>
						<text class="info-item-address-text">{{ infoItem.Address != 'undefined' ? infoItem.Address : '未获得定位信息' }}</text>
					</view>
					<view class="info-item-tel" @click.stop="callPhone(infoItemIndex)">
						<image src="../../static/infoIco/call.gif" mode="scaleToFill" class="info-item-telimg"></image>
						<text class="info-item-tel-text">拨打电话</text>
					</view>
				</view>
				<view class="info-item-release">
					<view class="info-item-time">
						{{ setTimeTxt(infoItem.ShiJian) }}
					</view>
					<!-- <view class="info-item-menu-location"> -->
						<view class="info-item-menu" v-if="infoItem.Menu == true">
							<view class="info-item-menu-report" @click.stop="gotoinfoReport(infoItemIndex)">
								<image src="../../static/infoIco/02.png" mode="scaleToFill" class="info-item-menu-reportimg"></image>
								<text class="info-item-menu-reporttext">举报</text>
							</view>
							
							<view class="info-item-menu-report" @click.stop="setInfoCollection(infoItemIndex)">
								<image src="../../static/infoIco/03.png" mode="scaleToFill" class="info-item-menu-collectimg" v-if="infoItem.IsSC == 0"></image>
								<image src="../../static/infoIco/SCCG.png" mode="scaleToFill" class="info-item-menu-collectimg" v-else-if="infoItem.IsSC == 1"></image>
								<text class="info-item-menu-collecttext">收藏</text>
							</view>
							
							<view class="info-item-menu-report" @click.stop="callPhone(infoItemIndex)">
								<image src="../../static/infoIco/04.png" mode="scaleToFill" class="info-item-menu-phoneimg"></image>
								<text class="info-item-menu-phonetext">电话</text>
							</view>
						</view>
					<!-- </view> -->
					<image src="../../static/infoIco/tim.png" mode="scaleToFill" class="info-item-menuimg" @click.stop="showInfoItemMenu" :id="infoItemIndex"></image>
				</view>
				
			</view>
		</block>
		<!-- <view class="info-item info-item-vip">
			<view class="info-item-head">
				<image src="../../static/tempimg/2011221222935630.png" alt="" class="info-userface" mode="aspectFill"></image>
				<view class="info-item-briefing">
					<view class="info-briefing-title">
						<view class="info-briefing-class">
							房屋出租
						</view>
						<view class="info-briefing-name">
							李先生
						</view>
					</view>
					<view class="info-briefing-tag">
						<view class="info-briefing-tag-item">
							学区房
						</view>
						<view class="info-briefing-tag-item">
							采光好
						</view>
						<view class="info-briefing-tag-item">
							交通便利
						</view>
						<view class="info-briefing-tag-item">
							位置安静
						</view>
					</view>
				</view>
			</view>
			<view class="info-item-content">
				大禹城邦电梯楼，釆光好视野宽阔学区房，(十三中，民主小学)设施齐全，精装修，可短租，价格面议，共三套可选择。<text class="info-item-content-more">查看全部>></text>
			</view>
			<view class="info-item-img-group">
				<image src="../../static/tempimg/2021051504249270.jpg" mode="aspectFill" class="info-item-img"></image>
				<image src="../../static/tempimg/2021051504300827.jpg" mode="aspectFill" class="info-item-img"></image>
				<image src="../../static/tempimg/2021051504341344.jpg" mode="aspectFill" class="info-item-img"></image>
				<image src="../../static/tempimg/2021051554455813.jpg" mode="aspectFill" class="info-item-img"></image>
				<image src="../../static/tempimg/2021051555102845.jpg" mode="aspectFill" class="info-item-img"></image>
				<image src="../../static/tempimg/21051512310268041.jpg" mode="aspectFill" class="info-item-img"></image>
			</view>
			<view class="info-item-addtel">
				<view class="info-item-addres">
					<image src="../../static/infoIco/map.png" mode="scaleToFill" class="info-item-addresimg"></image>
					<text class="info-item-address-text">吉林省通化市东昌区新光路吉林省通化市东昌区新光路吉林省通化市东昌区新光路</text>
				</view>
				<view class="info-item-tel">
					<image src="../../static/infoIco/call.gif" mode="scaleToFill" class="info-item-telimg"></image>
					<text class="info-item-tel-text">拨打电话</text>
				</view>
			</view>
			<view class="info-item-release">
				<view class="info-item-time">
					5分钟前 2021-05-15 14:34:56
				</view>
				<image src="../../static/infoIco/tim.png" mode="scaleToFill" class="info-item-menuimg"></image>
			</view>
			<view class="info-item-menu-location">
				<view class="info-item-menu">
					<view class="info-item-menu-report">
						<image src="../../static/infoIco/02.png" mode="scaleToFill" class="info-item-menu-reportimg"></image>
						<text class="info-item-menu-reporttext">举报</text>
					</view>
					
					<view class="info-item-menu-report">
						<image src="../../static/infoIco/03.png" mode="scaleToFill" class="info-item-menu-collectimg" v-if="isCollection"></image>
						<image src="../../static/infoIco/SCCG.png" mode="scaleToFill" class="info-item-menu-collectimg" v-else></image>
						<text class="info-item-menu-collecttext">收藏</text>
					</view>
					
					<view class="info-item-menu-report">
						<image src="../../static/infoIco/04.png" mode="scaleToFill" class="info-item-menu-phoneimg"></image>
						<text class="info-item-menu-phonetext">电话</text>
					</view>
				</view>
			</view>
		</view> -->
	</view>
</template>

<script>
	import {getDateDiff , getFormatTime} from '../../common/common.js'
	export default {
		name:"InformationItem",
		data() {
			return {
				isCollection:false,
				myInfoList:[],
			};
		},
		props: {
			infoList: {
				type: Array,
				default() {
					return [];
				}
			}
		},
		methods:{
			setTimeTxt(time){
				return getDateDiff(parseInt(time)*1000) + ' ' +  getFormatTime(parseInt(time), 'Y-M-D h:m:s')
			},
			showInfoItemMenu(e){
				this.myInfoList.forEach((el, index)=>{
					if(e.target.id != index){
						el = Object.assign(el,{'Menu':false})
					}
				})
				if (this.myInfoList[e.target.id].Menu === true) {
					this.myInfoList[e.target.id].Menu = false
				} else {
					this.myInfoList[e.target.id].Menu = true
				}
				this.$forceUpdate()  // 进行强制渲染,效果实现。
			},
			callPhone(index){
				uni.makePhoneCall({
				    phoneNumber: this.myInfoList[index].Phone //仅为示例
				});
			},
			gotoinfoReport(index) {
				let item = this.myInfoList[index];		 
				uni.navigateTo({
				  url: '../infoReport/infoReport?infoid=' + item.ID + "&classid=" + item.LanMuID,
				})
			 },
			 setInfoCollection(index){
				 let infoid = this.myInfoList[index].ID
				 this.$api.setInfoCollection({xxid:infoid, openid:getApp().globalData.openid})
				 .then(res =>{
					 console.log(res)
					 if (this.myInfoList[index].IsSC == 1){
						 this.myInfoList[index].IsSC = 0
					 }else{
						 this.myInfoList[index].IsSC = 1
					 }
					 this.$forceUpdate()  // 进行强制渲染,效果实现。
					 uni.showToast({
					 	title:res.msg,
						icon:'success',
					 })				 
				 })
			 },
			 infoimagePreview(index,infoindex){
				 let infoimages = []
				 this.myInfoList[infoindex].tpdata.forEach((tupianItem) =>{
					 infoimages.push(this.$getImgUrl(tupianItem.imgpath))
				 })
				 uni.previewImage({
					 current:index,
					 urls:infoimages,
				 })
			 },
			 gotoInfoContent(infoId){
				console.log(infoId)
				uni.navigateTo({
					url:'../../pages/infoContent/infoContent?infoId=' + infoId
				})
			 },

		},
		watch: {
			infoList: function(newVal, oldVal) {
				this.myInfoList = newVal;
				console.log(this.myInfoList)
			}
		}
	}
</script>

<style scoped>
@import url("InformationItem.css");
</style>
